import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class SignalConfig extends JFrame {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JTextField a_txt;
	private JTextField f_txt;
	private JTextField t0_txt;
	private JTextField d_txt;
	private Numerics nums;
	private Signal signal;
	private int nr;
	private JTextField T_txt;
	private JTextField kw_txt;
	private JTextField ts_txt;
	public int a;
	public short t0;
	double d;
	double t;
	double f;
	

	public SignalConfig(int signr, Numerics numz) {
		nums = numz;
		init(signr);
		setVisible(true);
		nr = signr;
	}

	public void init(int n) {
		setResizable(false);
		setBounds(100, 100, 343, 290);
		setTitle("Parametry tworzenia sygna\u0142u");

		JPanel panel = new JPanel();
		getContentPane().add(panel, BorderLayout.CENTER);
		panel.setLayout(null);

		JLabel lbl_a = new JLabel("Amplituda A:");
		lbl_a.setBounds(28, 39, 158, 14);
		panel.add(lbl_a);

		a_txt = new JTextField();
		a_txt.setBounds(229, 39, 86, 20);
		a_txt.setText("1");
		panel.add(a_txt);
		a_txt.setColumns(10);

		JLabel lbl_f = new JLabel(
				"Cz\u0119stotliwo\u015B\u0107 pr\u00F3bkowania fs:");
		lbl_f.setBounds(28, 197, 158, 14);
		panel.add(lbl_f);

		f_txt = new JTextField();
		f_txt.setColumns(10);
		f_txt.setBounds(229, 197, 86, 20);
		f_txt.setText("16");
		panel.add(f_txt);

		JLabel lbl_t0 = new JLabel("Czas pocz\u0105tkowy t0:");
		lbl_t0.setBounds(28, 14, 158, 14);
		panel.add(lbl_t0);

		t0_txt = new JTextField();
		t0_txt.setColumns(10);
		t0_txt.setBounds(229, 14, 86, 20);
		t0_txt.setText("0");
		panel.add(t0_txt);

		JLabel lbl_d = new JLabel("Czas trwania d:");
		lbl_d.setBounds(28, 64, 158, 14);
		panel.add(lbl_d);

		d_txt = new JTextField();
		d_txt.setColumns(10);
		d_txt.setBounds(229, 64, 86, 20);
		d_txt.setText("1");
		panel.add(d_txt);

		JButton btnGo = new JButton("Generuj sygna\u0142");
		btnGo.addMouseListener(new MouseAdapter() {
			@Override
			public void mousePressed(MouseEvent arg0) {
				generate(nr);
				dispose();
			}
		});
		btnGo.setBounds(75, 228, 105, 23);
		panel.add(btnGo);

		JButton btnCancel = new JButton("Anuluj");
		btnCancel.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				setVisible(false);
			}
		});
		btnCancel.setBounds(190, 228, 63, 23);
		panel.add(btnCancel);

		JLabel lbl_T = new JLabel("Cz\u0119stotliwo\u015Bc sygna\u0142u f0");
		lbl_T.setBounds(28, 105, 158, 14);
		panel.add(lbl_T);

		T_txt = new JTextField();
		T_txt.setColumns(10);
		T_txt.setBounds(229, 105, 86, 20);
		T_txt.setText("2");
		panel.add(T_txt);

		JLabel lblWsplczynnikWypelnieniaKw = new JLabel(
				"Wsp\u00F3lczynnik wypelnienia kw:");
		lblWsplczynnikWypelnieniaKw.setBounds(28, 130, 175, 14);
		panel.add(lblWsplczynnikWypelnieniaKw);

		kw_txt = new JTextField();
		kw_txt.setColumns(10);
		kw_txt.setBounds(229, 130, 86, 20);
		kw_txt.setText("0.5");
		panel.add(kw_txt);

		JLabel lbl_ts = new JLabel("Czas sygnalu ts:");
		lbl_ts.setBounds(28, 155, 158, 14);
		panel.add(lbl_ts);

		ts_txt = new JTextField();
		ts_txt.setText("2");
		ts_txt.setColumns(10);
		ts_txt.setBounds(229, 155, 86, 20);
		panel.add(ts_txt);

		a_txt.setEditable(false);
		t0_txt.setEditable(false);
		d_txt.setEditable(false);
		T_txt.setEditable(true);
		kw_txt.setEditable(false);
		ts_txt.setEditable(false);
		f_txt.setEditable(true);

		lbl_ts.setText("Czas sygnalu ts:");

		switch (n) {
		case 1:
			a_txt.setEditable(true);
			t0_txt.setEditable(true);
			d_txt.setEditable(true);
			break;
		case 2:
			a_txt.setEditable(true);
			t0_txt.setEditable(true);
			d_txt.setEditable(true);
			break;
		case 3:
			a_txt.setEditable(true);
			t0_txt.setEditable(true);
			d_txt.setEditable(true);
			T_txt.setEditable(true);
			break;
		case 4:
			a_txt.setEditable(true);
			t0_txt.setEditable(true);
			d_txt.setEditable(true);
			T_txt.setEditable(true);
			break;
		case 5:
			a_txt.setEditable(true);
			t0_txt.setEditable(true);
			d_txt.setEditable(true);
			T_txt.setEditable(true);
			break;
		case 6:
			a_txt.setEditable(true);
			t0_txt.setEditable(true);
			d_txt.setEditable(true);
			T_txt.setEditable(true);
			kw_txt.setEditable(true);
			break;
		case 7:
			a_txt.setEditable(true);
			t0_txt.setEditable(true);
			d_txt.setEditable(true);
			T_txt.setEditable(true);
			kw_txt.setEditable(true);
			break;
		case 8:
			a_txt.setEditable(true);
			t0_txt.setEditable(true);
			d_txt.setEditable(true);
			T_txt.setEditable(true);
			kw_txt.setEditable(true);
			break;
		case 9:
			a_txt.setEditable(true);
			t0_txt.setEditable(true);
			d_txt.setEditable(true);
			ts_txt.setEditable(true);
			break;
		case 10:
			a_txt.setEditable(true);
			t0_txt.setEditable(true);
			d_txt.setEditable(true);
			lbl_ts.setText("Numer probki skoku ns:");
			ts_txt.setEditable(true);
			f_txt.setEditable(true);
			f_txt.setText("10");
			break;
		case 11:
			a_txt.setEditable(true);
			t0_txt.setEditable(true);
			d_txt.setEditable(true);
			lbl_ts.setText("Prawdopodobienstwo p:");
			ts_txt.setText("0.25");
			ts_txt.setEditable(true);
			f_txt.setEditable(true);
			//f_txt.setText("10");
			break;
		}
	}

	public boolean generate(int nr) {
		double staticF = 10000;
		switch (nr) {
		case 1:
			setSignal(nums.s1(Integer.parseInt(a_txt.getText()),
					Short.parseShort(t0_txt.getText()),
					Integer.parseInt(d_txt.getText()), staticF));
			break;
		case 2:
			setSignal(nums.s2(Integer.parseInt(a_txt.getText()),
					Short.parseShort(t0_txt.getText()),
					Integer.parseInt(d_txt.getText()), staticF));
			break;
		case 3:
			setSignal(nums.s3(Integer.parseInt(a_txt.getText()),
					Short.parseShort(t0_txt.getText()),
					Double.parseDouble(d_txt.getText()),
					1.0/Double.parseDouble(T_txt.getText()),Double.parseDouble(f_txt.getText())));
					a = Integer.parseInt(a_txt.getText());
					t0 = Short.parseShort(t0_txt.getText());
					d = Double.parseDouble(d_txt.getText());
					t = 1.0/Double.parseDouble(T_txt.getText());
					f = Double.parseDouble(f_txt.getText());
			break;
		case 4:
			setSignal(nums.s4(Integer.parseInt(a_txt.getText()),
					Short.parseShort(t0_txt.getText()),
					Integer.parseInt(d_txt.getText()),
					Integer.parseInt(T_txt.getText()), staticF));
			break;
		case 5:
			setSignal(nums.s5(Integer.parseInt(a_txt.getText()),
					Short.parseShort(t0_txt.getText()),
					Integer.parseInt(d_txt.getText()),
					Integer.parseInt(T_txt.getText()), staticF));
			break;
		case 6:
			setSignal(nums.s6(Integer.parseInt(a_txt.getText()),
					Short.parseShort(t0_txt.getText()),
					Integer.parseInt(d_txt.getText()),
					Integer.parseInt(T_txt.getText()),
					Float.parseFloat(kw_txt.getText()), 200));
			break;
		case 7:
			setSignal(nums.s7(Integer.parseInt(a_txt.getText()),
					Short.parseShort(t0_txt.getText()),
					Integer.parseInt(d_txt.getText()),
					Integer.parseInt(T_txt.getText()),
					Float.parseFloat(kw_txt.getText()), staticF));
			break;
		case 8:
			setSignal(nums.s8(Integer.parseInt(a_txt.getText()),
					Short.parseShort(t0_txt.getText()),
					Integer.parseInt(d_txt.getText()),
					Integer.parseInt(T_txt.getText()),
					Float.parseFloat(kw_txt.getText()), staticF));
			break;
		case 9:
			setSignal(nums.s9(Integer.parseInt(a_txt.getText()),
					Short.parseShort(t0_txt.getText()),
					Integer.parseInt(d_txt.getText()),
					Double.parseDouble(ts_txt.getText()), staticF));
			break;
		case 10:
			setSignal(nums.s10(Integer.parseInt(a_txt.getText()),
					Short.parseShort(t0_txt.getText()),
					Integer.parseInt(d_txt.getText()),
					Double.parseDouble(ts_txt.getText()),
					Double.parseDouble(f_txt.getText())));
			break;
		case 11:
			setSignal(nums.s11(Integer.parseInt(a_txt.getText()),
					Short.parseShort(t0_txt.getText()),
					Integer.parseInt(d_txt.getText()),
					Float.parseFloat(ts_txt.getText()),
					Double.parseDouble(f_txt.getText())));
			break;
		}

		return true;

	}

	public void setSignal(Signal signal) {
		this.signal = signal;
	}

	public Signal getSignal() {
		return signal;
	}
}
